<template>
  <div>
    <TopFilter ref="bottomFilter" :list="topFilterList" :cols="4" :labelWidth="90" :rows="2" @filterChange="changeHandle" @onCollapse="collapseHandle"></TopFilter>

    <!-- :onRowSelectChange="columns => (this.selectColumns = columns)" -->
    <FilterTable
      ref="basetablewas"
      columnsRef="partInventoryManagerInventoryManagerIndex"
      :fetchapi="fetchApi"
      :columns="columns"
      :params="fetchParams"
      :onSyncTableData="tablechangeFun"
      :datakey="'rows'"
      :rowstyles="styleList"
      :onColumnsChange="columns => (this.columns = columns)"
      :onRowSelectChange="handleTableSelectChange"
      :defaultSelections="selectedRow"
      :onPageChange="handleTablePageChange"
    >
      <!-- selectionType="single" -->
      <template slot="controls">
        <!-- <el-button type="text" style="cursor: default">选中打印标签的配件：{{ selectPrintPartList.length }}</el-button> -->
        <multiuse-button size="small" type="primary" :auth-list="auths" auth-mark="/part/partstock/pGenPartMonreportTask" @click="handleCun()">执行月结</multiuse-button>
        <el-button v-if="appId == 'arcfox'" type="primary" @click="handleCun()">执行月结</el-button>
        <el-button type="primary" icon="el-icon-plus" @click="addFun()">新增</el-button>
        <el-button type="primary" :loading="exportBtnLoading" icon="el-icon-download" @click="handleaPullOut">导出</el-button>
        <UploadFile
          style="margin: 0 10px;"
          :initial-value="fileInitalValue"
          :limit="20"
          isOnlyButton
          type="primary"
          :actionUrl="`${server.DMSCLOUD_PART}/stockmanage/partmanage/importLocationModel`"
          @change="handleUploadChange"
          >库位更改导入</UploadFile
        >
        <el-button size="small" type="primary" @click="exportModel">库位更改模板</el-button>
        <!-- <el-button @click="saveDataFun">{{aaa?'停 用':'启 用'}}</el-button> -->
        <!-- <el-button type="primary" @click="clearLocation">清空库位</el-button> -->
        <!-- <AjaxButton type="primary" :click="handleMonthStatement">月结</AjaxButton> -->
        <!-- <el-button @click="saveDataFuns" type="primary">保 存</el-button> -->
        <!-- <el-button type="primary" @click="handlePrintLabel">打印标签</el-button> -->
      </template>
    </FilterTable>
    <!-- <br /> -->
    <!-- 为保证前端ui规范隐藏下方展示表单 -- hxj 2019/12/23 -->
    <FormPanel v-if="false" ref="form" :list="form" :cols="4" labelWidth="85" :isSubmitBtn="false" @formChange="formchangeFun" />

    <BaseDialog :visible.sync="addVisible" title="配件库存新增" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <addStock @close="closeHandle" @addChange="addChange" />
    </BaseDialog>
    <BaseDialog :visible.sync="emitVisible" title="配件库存编辑" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <emitStock :getdata="setEmitdata" @close="emitCloseHandle" @addChange="emitChange" />
    </BaseDialog>
    <BaseDialog :visible.sync="detailVisible" title="配件库存详情" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <detailStock :getdata="setDetaildata" @close="detailCloseHandle" />
    </BaseDialog>
    <div style="margin-top:40px">
      <FormPanel ref="form2" :labelWidth="120" :cols="4" :list="filterList2" :isSubmitBtn="false"></FormPanel>
    </div>

    <!-- 标签打印控件 -->
    <!-- <BasePrint ref="print" :data="labelPrintData" template="part/inventoryManager/labelPrintTemplate" /> -->
  </div>
</template>
<script>
import { dictionary } from '@/utils/dictMixin';
import moment from 'moment';
import SERVER from '@/api/server';
import {
  getpartStocksList,
  getfindStorageCode,
  newBuild,
  edit,
  save,
  clearPartLocation,
  handletableOne,
  handletableTwo,
  monthStatement,
  getAllInfo,
  getAllModel,
  clearStoragePositionAll,
  exportLocationModel
} from '@/api/part/inventoryManager/inventoryManager/index';
import { findAllRepair } from '@/api/repair/basicParameters';
import { getStorageList, exportData } from '@/api/part/common';
import addStock from './addStock.vue';
import { getBrandList } from '@/api/common/cars/masterDataCars';
import emitStock from './emitStock.vue';
import detailStock from './detailStock.vue';
import { confirmAction, notifyAction, arrayObjDeWeight, exportExcelFile } from '@/utils';
import { queryUnitCode } from '@/api/repair/batchEventManagement/activityDistribution';
import { authority } from '@/utils/authMixin';
import { getAppId } from '@/assets/js/auth';

export default {
  name: 'zjinventoryIndex',
  components: {
    addStock,
    emitStock,
    detailStock
  },
  mixins: [dictionary, authority],
  data() {
    this.baseTable = null;
    return {
      fetchApi: getpartStocksList,
      fetchParams: { xhrAbort: true },
      addVisible: false,
      emitVisible: false,
      detailVisible: false,
      topFilterList: this.createTopFilterList(),
      form: this.createForm(),
      columns: this.createTable(),
      filterList2: this.createTopFilterList2(),
      setEmitdata: {},
      setDetaildata: {},
      selectColumns: [],
      appId: getAppId(),
      exportBtnLoading: false,
      aaa: 1,
      styleList: [],
      questionList: [],
      // 打印标签数据
      labelPrintData: {
        partList: []
      },
      fileInitalValue: [],
      server: SERVER,
      selectedRow: [], // 选中的行项目
      tablePage: 1, // table页码
      selectPrintPartList: [], // 选中的打印项目
      pageSelectRows: [] // 当前页选中的行项(过滤取消勾选项用)
    };
  },
  created() {
    // this.getBrandList();
  },
  mounted() {
    this.checkId();
    window.asd = this;
    this.baseTable = this.$refs.basetablewas.$refs.pageTable;
    this.getUnit();
  },
  methods: {
    async getBrandList() {
      const res = await getBrandList();
      this.form.find(item => item.fieldName == 'brand').itemList = res.data.map(x => ({ text: x.brandName, value: x.brandCode }));
      this.columns.find(item => item.dataIndex == 'brand').editItems = res.data.map(x => ({ text: x.brandName, value: x.brandCode }));
    },
    async clearLocation() {
      try {
        console.log('清空库位');
        await confirmAction();

        // clearStoragePositionAll
        let obj = this.selectColumns.map(x => {
          return {
            storageCode: x.storageCode,
            partNo: x.partNo
          };
        });
        const res = await clearStoragePositionAll(obj);

        // const res = await clearPartLocation(this.selectColumns[0].partNo, this.selectColumns[0].storageCode);
        if (res.resultCode === 200) {
          if (res.data.success.length) {
            notifyAction('操作成功！', 'success');
            // 刷新页面
            this.fetchParams = { ...this.fetchParams };
          }
          // this.$message({
          //   message: res.data.msg,
          //   type: 'success'
          // });
        }
      } catch (error) {
        console.log(error);
      }
    },
    createTopFilterList() {
      return [
        {
          type: 'SELECT',
          label: '仓库',
          fieldName: 'STORAGE_CODE1',
          request: {
            fetchApi: getStorageList,
            valueKey: 'STORAGE_CODE',
            textKey: 'STORAGE_NAME'
          }
        },
        {
          type: 'INPUT',
          label: '配件代码',
          fieldName: 'PART_NO'
        },
        {
          type: 'INPUT',
          label: '配件名称',
          fieldName: 'PART_NAME'
        },
        {
          type: 'INPUT',
          label: '库位代码',
          fieldName: 'STORAGE_POSITION_CODE'
        },
        {
          type: 'SELECT',
          label: '可用库存大于0',
          fieldName: 'USEABLE_STOCK',
          // labelWidth: 150,
          itemList: this.createDictList('1004')
        },
        // {
        //   type: 'SELECT',
        //   label: '主数据已停用且本地库存为0',
        //   labelWidth: '165px',
        //   fieldName: 'KUCUN',
        //   initialValue: '',
        //   itemList: this.createDictList('1004')
        // },
        {
          type: 'SELECT',
          label: '配件属性',
          hidden: false,
          fieldName: 'PART_TYPE',
          itemList: this.createDictList('5000')
        },
        // {
        //   type: 'SELECT',
        //   label: '九大类',
        //   fieldName: 'PART_MAIN_TYPE',
        //   itemList: this.createDictList('8094')
        // },
        // {
        //   type: 'INPUT',
        //   label: '拼音代码',
        //   fieldName: 'SPELL_CODE'
        // },
        // {
        //   type: 'INPUT',
        //   label: '备注',
        //   fieldName: 'REMARK'
        // },
        {
          type: 'SELECT',
          label: '低于安全库存',
          fieldName: 'IS_SAFE',
          itemList: [
            { text: '是', value: '10041001' },
            { text: '否', value: '10041002' }
          ]
        },
        {
          type: 'CHECKBOX',
          label: '锁定数量大于0',
          fieldName: 'LOCKED_QUANTITY',
          initialValue: '10041002',
          options: {
            trueValue: '10041001',
            falseValue: '10041002'
          }
        }
        // {
        //   type: 'SELECT',
        //   label: '是否停用',
        //   fieldName: 'PART_STATUS',
        //   initialValue: '',
        //   itemList: this.createDictList('1004')
        // },

        // {
        //   type: 'SELECT',
        //   label: '建议销售价',
        //   fieldName: 'NOT_TAX_INSTRUCT_PRICE',
        //   initialValue: '',
        //   itemList: []
        // },
      ];
    },
    createTable() {
      return [
        {
          title: '操作',
          dataIndex: 'column-action',
          fixed: 'left',
          width: 100,
          render: (props, h) => {
            return (
              <div>
                <el-button size="mini" type="text" onClick={() => this.emitFun(props.row)} disabled={this.isEmit(props)}>
                  编辑
                </el-button>
              </div>
              // <el-divider direction="vertical" />
              //  <el-button size="mini" type="text" onClick={() => this.delFun(props.row)} disabled={props.row.flg == 'A' ? false : true}>
              //     删除
              //   </el-button>
            );
          }
        },
        {
          title: '序号',
          dataIndex: 'index',
          sorter: true,
          width: 70,
          render: props => {
            return <span>{props.row.$index + 1}</span>;
          }
        },

        {
          title: '仓库代码',
          dataIndex: 'storageCode',
          sorter: true,
          filter: true,
          filterType: 'input',
          // width: 110,
          showOverflowTooltip: true,
          render: props => {
            return <span>{props.row.storageCode}</span>;
          }
        },
        {
          title: '仓库名称',
          dataIndex: 'storageName',
          // width: 110,
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true,
          render: props => {
            return <span>{props.row.storageName}</span>;
          }
        },
        {
          title: '仓库类型',
          dataIndex: 'storageType',
          // width: 110,
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          showOverflowTooltip: true,
          filterItems: this.createDictList(5000),
          dictItems: this.createDictList(5000)
        },
        {
          title: '库位代码',
          dataIndex: 'storagePositionCode',
          sorter: true,
          // width: 110,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true,
          render: props => {
            return <span>{props.row.storagePositionCode}</span>;
          }
        },
        {
          title: '配件代码',
          dataIndex: 'partNo',
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true,
          render: props => {
            return <span>{props.row.partNo}</span>;
          }
        },
        {
          title: '配件名称',
          dataIndex: 'partName',
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true,
          render: props => {
            return <span>{props.row.partName}</span>;
          }
        },
        {
          title: '可用库存',
          dataIndex: 'useableStock',
          sorter: true,
          filter: true,
          filterType: 'number',
          precision: 2,
          showOverflowTooltip: true,
          width: 110
          // render: props => {
          //   return <span>{props.row.useableStock}</span>;
          // }
        },
        {
          title: '库存数量',
          dataIndex: 'stockQuantity',
          sorter: true,
          filter: true,
          precision: 2,
          showOverflowTooltip: true,
          filterType: 'number',
          width: 110
          // render: props => {
          //   return <span>{props.row.stockQuantity}</span>;
          // }
        },
        {
          title: '预留数量',
          dataIndex: 'reservedQuantity',
          sorter: true,
          filter: true,
          precision: 2,
          // showOverflowTooltip: true,
          filterType: 'number',
          width: 110
          // render: props => {
          //   return <span>{props.row.lockedQuantity}</span>;
          // }
        },
        // {
        //   title: '最小包装数量',
        //   dataIndex: 'packageLiaght',
        //   sorter: true,
        //   filter: true,
        //   showOverflowTooltip: true,
        //   filterType: 'input'
        //   // render: props => {
        //   //   return <span>{props.row.stockQuantity}</span>;
        //   // }
        // },
        // {
        //   title: '终端建议零售VIP价格',
        //   // title: '销售价',
        //   dataIndex: 'salesPrice',
        //   sorter: true,
        //   filter: true,
        //   precision: 2,
        //   filterType: 'number'
        //   // render: props => {
        //   //   return <span>{props.row.salesPrice}</span>;
        //   // }
        // },
        // {
        //   title: '建议销售价',
        //   dataIndex: 'notTaxInstructPrice',
        //   sorter: true,
        //   filter: true,
        //   render: props => {
        //     return <span>{props.row.notTaxInstructPrice}</span>;
        //   }
        // },
        // {
        //   title: '含税出库单价',
        //   // title: '出库单价',
        //   dataIndex: 'costOutPrice',
        //   sorter: true,
        //   filter: true,
        //   precision: 2,
        //   filterType: 'number'
        //   // render: props => {
        //   //   return <span>{props.row.costOutPrice}</span>;
        //   // }
        // },
        // {
        //   title: '含税批发价',
        //   dataIndex: 'costWholesalesPrice',
        //   // dataIndex: 'wholesalesPrice',
        //   sorter: true,
        //   filter: true,
        //   precision: 2,
        //   filterType: 'number'
        //   // render: props => {
        //   //   return <span>{props.row.wholesalesPrice}</span>;
        //   // }
        // },
        {
          title: '含税成本单价',
          dataIndex: 'costPrice',
          sorter: true,
          filter: true,
          precision: 2,
          filterType: 'number'
          // render: props => {
          //   return <span>{props.row.costPrice}</span>;
          // }
        },
        {
          title: '配件类别',
          dataIndex: 'partGroupCode',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('8247'),
          render: props => {
            return <span>{this.createDictText(props.row.partGroupCode, '8247')}</span>;
          }
        },
        // {
        //   title: '拼音代码',
        //   dataIndex: 'spellCode',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'input'
        //   // render: props => {
        //   //   return <span>{props.row.spellCode}</span>;
        //   // }
        // },
        {
          title: '单位',
          dataIndex: 'unitCode',
          sorter: true,
          filterType: 'checkbox',
          dictItems: []
          // render: props => {
          //   return <span>{props.row.unitName}</span>;
          // }
        },
        {
          title: '在库天数',
          dataIndex: 'inStorageDay',
          sorter: true,
          filterType: 'input'
          // render: props => {
          //   return <span>{props.row.unitName}</span>;
          // }
        },
        {
          title: '调拨在途数量',
          dataIndex: 'notInQuantity',
          sorter: true,
          filterType: 'input'
          // render: props => {
          //   return <span>{props.row.unitName}</span>;
          // }
        },
        // {
        //   title: '终端建议零售价格',
        //   dataIndex: 'insurancePrice',
        //   sorter: true,
        //   filter: true,
        //   precision: 2,
        //   filterType: 'number'
        //   // render: props => {
        //   //   return <span>{props.row.insurancePrice}</span>;
        //   // }
        // },
        // {
        //   title: '索赔价',
        //   dataIndex: 'claimPrice',
        //   sorter: true,
        //   filter: true,
        //   precision: 2,
        //   filterType: 'number'
        //   // render: props => {
        //   //   return <span>{props.row.claimPrice}</span>;
        //   // }
        // },
        // {
        //   title: '销售限价',
        //   dataIndex: 'limitPrice',
        //   sorter: true,
        //   filter: true,
        //   precision: 2,
        //   filterType: 'number'
        //   // render: props => {
        //   //   return <span>{props.row.limitPrice}</span>;
        //   // }
        // },
        {
          title: '锁定数量',
          dataIndex: 'lockedQuantity',
          sorter: true,
          filter: true,
          precision: 2,
          filterType: 'number'
          // render: props => {
          //   return <span>{props.row.lockedQuantity}</span>;
          // }
        },
        // {
        //   title: '最大库存',
        //   dataIndex: 'maxStock',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'number',
        //   precision: 2
        //   // render: props => {
        //   //   return <span>{props.row.maxStock}</span>;
        //   // }
        // },
        {
          title: '安全库存',
          dataIndex: 'safeStock',
          sorter: true,
          filter: true,
          filterType: 'number',
          precision: 2
          // render: props => {
          //   return <span>{props.row.safeStock}</span>;
          // }
        },
        // {
        //   title: '最小库存',
        //   dataIndex: 'minStock',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'number',
        //   precision: 2
        //   // render: props => {
        //   //   return <span>{props.row.minStock}</span>;
        //   // }
        // },
        {
          title: '最小包装数',
          dataIndex: 'minPackage',
          sorter: true,
          filter: true,
          filterType: 'input'
          // render: props => {
          //   return <span>{props.row.minPackage}</span>;
          // }
        },
        // {
        //   title: '产地',
        //   dataIndex: 'productingArea',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'input'
        //   // render: props => {
        //   //   return <span>{props.row.productingArea}</span>;
        //   // }
        // },
        {
          title: '含税成本金额',
          dataIndex: 'costAmount',
          sorter: true,
          filter: true,
          filterType: 'number',
          precision: 2
          // render: props => {
          //   return <span>{props.row.costAmount}</span>;
          // }
        },
        {
          title: '最新入库日期',
          dataIndex: 'lastStockIn',
          sorter: true,
          filter: true,
          filterType: 'date-range'
          // render: props => {
          //   return <span>{props.row.lastStockIn}</span>;
          // }
          // dateFormat: 'yyyy-MM-dd'
        },
        {
          title: '最新出库日期',
          dataIndex: 'lastStockOut',
          sorter: true,
          filter: true,
          filterType: 'date-range'
          // render: props => {
          //   return <span>{props.row.lastStockOut}</span>;
          // }
        },
        // {
        //   title: '替代配件',
        //   // dataIndex: 'optionNo',
        //   dataIndex: 'optionName',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'input'
        //   // render: props => {
        //   //   return <span>{props.row.optionName}</span>;
        //   // }
        // },
        // {
        //   title: '品牌',
        //   dataIndex: 'brand',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'input',
        //   disabled: true,
        //   editable: true,
        //   editType: 'select',
        //   editItems: []
        // },
        {
          title: '是否停用',
          dataIndex: 'partStatus',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('1004'),
          render: props => {
            return <span>{this.createDictText(props.row.partStatus, '1004')}</span>;
          }
        },
        {
          title: '备注',
          dataIndex: 'remark',
          sorter: true,
          filter: true,
          filterType: 'input',
          render: props => {
            return <span>{props.row.remark}</span>;
          }
        },
        // {
        //   title: '九大类',
        //   dataIndex: 'partMainType',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'checkbox',
        //   filterItems: this.createDictList('8094'),
        //   render: props => {
        //     return <span>{this.createDictText(props.row.partMainType, '8094')}</span>;
        //   }
        // },
        // {
        //   title: '不含税成本单价',
        //   dataIndex: 'netCostPrice',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'number',
        //   precision: 2
        //   // render: props => {
        //   //   return <span>{props.row.netCostPrice}</span>;
        //   // }
        // },
        // {
        //   title: '不含税成本金额',
        //   dataIndex: 'netCostAmount',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'number',
        //   precision: 2
        //   // render: props => {
        //   //   return <span>{props.row.netCostAmount}</span>;
        //   // }
        // },
        {
          title: '数据来源',
          dataIndex: 'oemTag',
          sorter: true,
          filter: true,
          filterItems: this.createDictList(1045, [10451003]),
          filterType: 'checkbox',
          // initialValue: 'OEM/店端',
          render: props => {
            return <span>{this.createDictText(props.row.oemTag, '1045')}</span>;
          }
        }
      ];
    },
    createForm() {
      return [
        {
          type: 'INPUT',
          label: '仓库',
          fieldName: 'storageName',
          disabled: true
        },
        {
          type: 'INPUT_NUMBER',
          label: '销售价',
          fieldName: 'salesPrice',
          precision: 2,
          disabled: true
        },
        {
          type: 'INPUT_NUMBER',
          label: '出库单价',
          fieldName: 'costOutPrice',
          precision: 2,
          disabled: true
        },
        {
          type: 'INPUT',
          label: '配件名称',
          fieldName: 'partName',
          disabled: true
        },
        {
          type: 'INPUT_NUMBER',
          precision: 2,
          label: '成本单价',
          fieldName: 'costPrice',
          disabled: true
        },
        {
          type: 'INPUT_NUMBER',
          precision: 2,
          label: '账面库存',
          fieldName: 'stockQuantity',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '库位代码',
          fieldName: 'storagePositionCode',
          disabled: true
        },
        // {
        //   type: 'INPUT',
        //   label: '建议销售价',
        //   fieldName: 'notTaxInstructPrice',
        //   disabled: true
        // },
        // {
        //   type: 'INPUT_NUMBER',
        //   precision: 2,
        //   label: '批发价',
        //   fieldName: 'wholesalesPrice',
        //   disabled: true
        // },
        // {
        //   type: 'INPUT',
        //   label: '拼音代码',
        //   fieldName: 'spellCode',
        //   disabled: true
        // },
        {
          type: 'INPUT_NUMBER',
          precision: 2,
          label: '成本金额',
          fieldName: 'costAmount',
          disabled: true
        },
        {
          type: 'INPUT_NUMBER',
          precision: 2,
          label: '锁定量',
          fieldName: 'lockedQuantity',
          disabled: true
        },
        {
          type: 'SELECT',
          label: '配件类别',
          fieldName: 'partGroupCode',
          itemList: this.createDictList('8247'),
          disabled: true
        },
        {
          type: 'INPUT_NUMBER',
          precision: 2,
          label: '索赔价',
          fieldName: 'claimPrice',
          disabled: true
        },
        // {
        //   type: 'INPUT',
        //   label: '替代配件',
        //   // fieldName: 'optionNo',
        //   fieldName: 'optionName',
        //   disabled: true
        // },
        {
          type: 'INPUT_NUMBER',
          precision: 2,
          label: '终端建议零售价格',
          fieldName: 'insurancePrice',
          disabled: true
        },
        {
          type: 'INPUT_NUMBER',
          precision: 2,
          label: '可用库存',
          fieldName: 'useableStock',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '配件代码',
          fieldName: 'partNo',
          disabled: true
        },
        {
          type: 'INPUT_NUMBER',
          precision: 2,
          label: '最新进货价',
          fieldName: 'latestPrice',
          disabled: true
        },
        // {
        //   type: 'INPUT',
        //   label: '建档日期',
        //   fieldName: 'foundDate',
        //   // valueFormat: 'yyyy-MM-dd',
        //   disabled: true
        // },
        {
          type: 'INPUT',
          label: '是否停用',
          fieldName: 'partStatus',
          disabled: true
          // itemList: this.createDictText('1004')
        },
        {
          type: 'INPUT',
          label: '最新出库日期',
          fieldName: 'lastStockOut',
          disabled: true
        },
        // {
        //   type: 'SELECT',
        //   label: '品牌',
        //   fieldName: 'brand',
        //   itemList: [],
        //   disabled: true
        // },
        {
          type: 'INPUT',
          label: '最新入库日期',
          fieldName: 'lastStockIn',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '备注',
          fieldName: 'remark',
          initialValue: '',
          disabled: true
        }
      ];
    },
    createTopFilterList2() {
      return [
        // {
        //   type: 'INPUT',
        //   label: '领料合计金额',
        //   fieldName: 'edtMoney',
        //   precision: 2,
        //   disabled: true
        // },
        {
          type: 'INPUT',
          label: '合计数量',
          precision: 2,
          fieldName: 'allQuantity',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '合计成本金额',
          precision: 2,
          fieldName: 'allCostAmount',
          disabled: true
        }
      ];
    },
    // 执行月结
    async handleCun() {
      const resOne = await handletableOne();
      // const resTwo = await handletableTwo();
      if (resOne.resultCode == 200) {
        this.$notify.success({ title: '提示信息', message: '执行月结成功!' });
      }
    },
    // async getStorage() {
    //   const res = await getStroageList();
    //   // let resdata = await findAllRepair();
    //   this.topFilterList.find(item => item.fieldName === 'STORAGE_CODE1').itemList = res.data.map(x => ({ text: x.STORAGE_NAME, value: x.STORAGE_CODE }));
    // },
    // 搜索
    async changeHandle(val) {
      let searchData = _.cloneDeep(val);
      console.log(searchData.STORAGE_POSITION_CODE);

      if (searchData.STORAGE_POSITION_CODE) {
        // if (searchData.STORAGE_POSITION_CODE.indexOf('_') != -1) {
        //   searchData.RESERVOIR_AREA = searchData.STORAGE_POSITION_CODE.slice(0, searchData.STORAGE_POSITION_CODE.indexOf('_'));
        // } else {
        //   searchData.RESERVOIR_AREA = searchData.STORAGE_POSITION_CODE;
        // }
        // searchData.STORAGE_POSITION_CODE = undefined;
        // } else {
        //   searchData.RESERVOIR_AREA = undefined;
      }
      console.log('搜索', searchData);
      searchData.searchType = 1;
      this.fetchParams = Object.assign({}, searchData);
      this.pageSelectRows = [];
      let res = await getAllInfo(this.fetchParams);
      if (res.resultCode == 200) {
        this.filterList2.find(x => {
          x.initialValue = Number(res.data[x.fieldName]).toFixed(2);
        });
      }
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.$refs.basetablewas.EXECUTE_RESET_HEIGHT();
      });
    },
    exportModel() {
      exportLocationModel().then(res => {
        console.log('res:::', res);
        exportExcelFile(res.data, '库位更改模板');
      });
    },
    // 双击显示
    tableDbclickFun(val) {
      console.log('打印了呀', val);
      this.form.forEach(x => {
        x.initialValue = val[x.fieldName];
      });
      if (val.foundDate != null && val.foundDate != '') {
        this.form.find(item => item.fieldName === 'foundDate').initialValue = moment(val.foundDate).format('YYYY-MM-DD');
        // this.form[17].initialValue = moment(val.foundDate).format('YYYY-MM-DD');
      }
      let partStatus = val.partStatus == 10041001 ? '是' : '否';
      this.form.find(item => item.fieldName === 'partStatus').initialValue = partStatus;
      // this.form[18].initialValue = partStatus;
    },
    formchangeFun(val) {},
    // table数据变化
    tablechangeFun(val) {
      let appId = getAppId();
      val.forEach(item => (item.partNoPosCode = item.partNo + item.storagePositionCode)); // 将配件代码及库位代码拼接(作为行项唯一标识)
      val.forEach(x => {
        if (x.safeStock != null && x.safeStock != undefined && x.safeStock != '' && Number(x.safeStock) > Number(x.stockQuantity)) {
          this.styleList.push({ row: x, styles: { backgroundColor: '#ffd200' } });
        } else if (x.maxStock != null && x.maxStock != undefined && x.maxStock != '' && Number(x.maxStock) != 0 && Number(x.maxStock) < Number(x.stockQuantity) && appId == 'arcfox') {
          this.styleList.push({ row: x, styles: { backgroundColor: '#f70000' } });
        } else {
          this.styleList = this.styleList.filter(y => y.row != x);
        }
      });
      this.questionList = val;
      this.selectedRow = val.filter(item => !!this.selectPrintPartList.find(x => x.partNoPosCode == item.partNoPosCode));
      console.log(this.selectedRow, '页面数据变化重新赋值选中行项');
    },
    addFun() {
      this.addVisible = true;
    },
    emitFun(data) {
      console.log('打压', data);
      this.setEmitdata = data;
      this.emitVisible = true;
    },
    detailFun(data) {
      this.setDetaildata = data;
      this.detailVisible = true;
      // this.selectColumns[0]=data;
    },
    // 点击导出
    async handleaPullOut() {
      if (this.exportBtnLoading) return;
      this.exportBtnLoading = true;
      let queryData = (await this.$refs.bottomFilter.GET_FORM_DATA())[1];
      let res = await exportData(queryData);
      this.exportBtnLoading = false;
      exportExcelFile(res.data, '配件库存管理导出');
    },
    delFun(data) {
      this.baseTable.EXECUTE_DELETE([data]);
    },
    closeHandle(val) {
      // 关闭
      this.addVisible = false;
    },
    addChange(val) {
      // 添加成功
      console.log(1123);
      this.addVisible = false;
      // 刷新
      this.fetchParams = { ...this.fetchParams };
      this.columns = [...this.columns];
    },
    emitChange(val, index) {
      console.log(val, 'table值');
      console.log(index, 'index');
      this.emitVisible = false;
      this.fetchParams = { ...this.fetchParams };
      //  this.selectColumns[0].storageName='11110';
    },
    emitCloseHandle() {
      this.emitVisible = false;
    },
    detailCloseHandle() {
      this.detailVisible = false;
    },
    handleUploadChange(e) {
      console.log('e:::', e);
      if (e != 1) {
        this.fileInitalValue = e;
        let successList = _.cloneDeep(e[e.length - 1].url.successList);
        let infoFailList = _.cloneDeep(e[e.length - 1].url.infoFailList);
        let sameFailList = _.cloneDeep(e[e.length - 1].url.sameFailList);
        let locationFailList = _.cloneDeep(e[e.length - 1].url.locationFailList);
        let res = '';
        if (successList.length > 0) {
          res = '更新成功' + successList.length + '条\n';
        }
        if (infoFailList.length > 0) {
          let parts = infoFailList.map(i => i.partNo).join(',');
          res = res + '更新失败' + infoFailList.length + '条,配件在仓库中没有信息,配件代码为' + parts;
        }
        if (sameFailList.length > 0) {
          let parts = sameFailList.map(i => i.partNo).join(',');
          res = res + '更新失败' + sameFailList.length + '条,配件存在冲突库位,配件代码为' + parts;
        }
        if (locationFailList.length > 0) {
          let parts = locationFailList.map(i => i.partNo).join(',');
          res = res + '更新失败' + locationFailList.length + '条,没有信息库位信息,配件代码为' + parts;
        }
        notifyAction(res, 'success');
        this.fetchParams = { ...this.fetchParams };
      }
    },
    saveDataFun() {
      // console.log(this.aaa)
      this.selectColumns[0].partStatus = this.selectColumns[0].partStatus == '10041002' ? '10041001' : '10041002';
      console.log(this.selectColumns[0].partStatus);
      // 修改按钮
      this.aaa = this.aaa == 1 ? 0 : 1;
    },
    async saveDataFuns() {
      this.$confirm('是否确认保存?', '提示', {
        confirmButtonText: '确认',
        cancelButtonText: '取消',
        type: 'warning'
      });
      // this.
      let obj = { dmstable: this.questionList };
      obj = JSON.parse(JSON.stringify(obj));
      let res = await save(obj);
      console.log('保存了', res);
    },
    isEmit(data) {
      return false;
    },
    isDetail(data) {
      return false;
    },
    // isDel(data) { }
    // 点击月结
    async handleMonthStatement() {
      let res = await monthStatement();
    },
    async getUnit() {
      const res = await queryUnitCode();
      console.log('getUnit res::', res);
      let data = arrayObjDeWeight(res.data, 'UNIT_CODE');
      this.columns.find(x => x.dataIndex == 'unitCode').dictItems = data.map(x => ({ value: x.UNIT_CODE + '', text: x.UNIT_NAME }));
    },
    // 打印标签
    handlePrintLabel() {
      if (!this.selectPrintPartList.length) {
        notifyAction('请选择需要打印的配件', 'warning');
      } else {
        confirmAction(`选中的配件${this.selectPrintPartList.map(item => item.partNo).join(',')}是否确认打印？`, 'warning')
          .then(e => {
            let printData = this.selectPrintPartList.map(item => ({
              partNo: item.partNo,
              partName: item.partName,
              storageInfo: item.storageCode,
              storageArea: item.storagePositionCode.split('_')[0],
              storagePosition: item.storagePositionCode.split('_')[1] || ''
            }));
            this.labelPrintData.partList = printData;
            this.$refs.print.EXCUTE_PRINT();
            // 打印清空选中的配件及选中的行项
            this.selectPrintPartList = [];
            this.$refs.basetablewas.DO_REFRESH(false);
          })
          .catch(err => {});
      }
    },
    // table页码变化
    handleTablePageChange(e) {
      this.tablePage = e.pageNum;
      this.pageSelectRows = [];
    },
    async checkId() {
      let appId = await getAppId();
      if (appId == 'arcfox') {
        this.topFilterList.find(x => x.fieldName == 'PART_TYPE').hidden = true;
      }
    },
    // table行项选中变化
    handleTableSelectChange(e) {
      this.selectColumns = e;

      // 跨页跨搜索逻辑
      let deleteRows = this.pageSelectRows.filter(item => !e.find(x => x.partNo == item.partNo)); // 需要从打印列表中删除的行项（取消选择的行项）
      this.pageSelectRows = e;
      console.log(deleteRows, '删除的行项');
      this.selectPrintPartList = this.selectPrintPartList.filter(item => !deleteRows.find(x => x.partNo == item.partNo)); // 删除取消勾选的行项

      let totalPartList = [...this.selectPrintPartList, ...e];
      this.selectPrintPartList = arrayObjDeWeight(totalPartList, 'partNoPosCode');
      console.log(this.selectPrintPartList, '行项选中变化');
    }
  }
};
</script>

<style scoped lang="less"></style>
